package myStack.impl;

import myStack.IStack;

import java.lang.reflect.Array;


/**
 * 栈
 * Created by Administrator on 2017/3/16.
 */
public class StackImpl<E> implements IStack<E> {
    private E[] stack;  //新建栈
    private int size;   //长度
    private int maxSize;//最大长度（栈容量）

    public StackImpl(Class<E> type, int maxSize) {
        stack = (E[]) Array.newInstance(type, maxSize);
        this.maxSize = maxSize;
        size = 0;
    }

    /**
     * 压栈（顺序表的开头插入元素）
     * @param item 元素
     * @return
     */
    @Override
    public E push(E item) {
        if (!isEmpty()) {
            for (int i = size; i >0 ; i--) {
                stack[i]=stack[i-1];
            }
        }
        stack[0] = item;
        size++;
        return null;
    }

    @Override
    public E pop() {
        return null;
    }

    @Override
    public E peek() {
        return null;
    }

    @Override
    public int size() {
        return size;
    }

    @Override
    public boolean isEmpty() {
        return size==0;
    }

    @Override
    public boolean isFull() {
        return size==maxSize;
    }
}
